package com.ncloud.resman.mapper;



import java.sql.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.resman.entity.RepairRecord;


/**
 * user:sundelong  date:2017年8月11日
 */
@Mapper
public interface RepairRecordMapper {
	@Select(value = {"select id,f_get_dict('eqpt_type',eqpt_type) as eqpt_type,sn_id,f_get_dict('repair_state',"
			+ "repair_state) as repair_state,solution,repair_date,create_user,create_date,update_date,remark "
			+ "from res_repair_record  order by repair_date desc"})	
	@Results({
		@Result(column="id",property="id"),@Result(column="eqpt_type",property="eqptType"),
		@Result(column="sn_id",property="snId"),@Result(column="repair_state",property="repairState",javaType=String.class),
		@Result(column="solution",property="solution"),@Result(column="repair_date",property="repairDate",javaType=Date.class),
		@Result(column="create_user",property="createUser"),@Result(column="create_date",property="createDate"),
		@Result(column="update_user",property="updateUser"),@Result(column="update_date",property="updateDate"),
		@Result(column="remark",property="remark")})
	List<RepairRecord> getRepairList();
	
	
	
	@Select(value = {"select id,f_get_dict('eqpt_type',eqpt_type) as eqpt_type,sn_id,f_get_dict('repair_state',repair_state) "
			+ "as repair_state,solution,repair_date,create_user,create_date,update_date,remark from res_repair_record "
			+ "where (#{0}=0 or eqpt_type=#{0}) and sn_id like concat('%',#{1},'%') "
			+ "and (#{2}=2 or repair_state=#{2})  and (#{3}=0 or repair_date > #{3}) and (#{4}=0 or repair_date < #{4})"})	
	@Results({
		@Result(column="id",property="id"),@Result(column="eqpt_type",property="eqptType"),
		@Result(column="sn_id",property="snId"),@Result(column="repair_state",property="repairState",javaType=String.class),
		@Result(column="solution",property="solution"),@Result(column="repair_date",property="repairDate",javaType=Date.class),
		@Result(column="create_user",property="createUser"),@Result(column="create_date",property="createDate"),
		@Result(column="update_user",property="updateUser"),@Result(column="update_date",property="updateDate"),
		@Result(column="remark",property="remark")})
	List<RepairRecord> getRepairInfoBySnId(String eqptType,String snId,String repairState,String beginDate,String endDate);
	
	@Insert(value = {"insert into res_repair_record(eqpt_type,sn_id,repair_state,solution,repair_date,"
			+ "create_user,create_date,update_user,update_date,remark) values (#{eqptType},#{snId},#{repairState}"
			+ ",#{solution},#{repairDate},#{createUser},now(),#{updateDate},now(),#{remark})"})	
	int insertRepair(RepairRecord repairRecord);
	
	@Update(value = {"update res_repair_record set eqpt_type=#{0},sn_id=#{1} ,repair_state=#{2},solution=#{3},"
			+ "update_user=#{4},update_date=now() where eqpt_type=#{5} and sn_id=#{6} and repair_state=#{7}"})
	int updateRepair2(String eqptType,String snId,String repairState,String solution,String updateUser,String eqptType_O,String OsnId_O,String OrepairState_O);
	
	@Update(value = {"update res_repair_record set eqpt_type=#{0},sn_id=#{1} ,repair_state=#{2},solution=#{3},"
			+ "update_user=#{4},update_date=now() where id=#{5}"})
	int updateRepair(String eqptType,String snId,String repairState,String solution,String updateUser,String id);
	
	@Delete(value = {"delete from res_repair_record where eqpt_type=#{0} and sn_id=#{1} and repair_state=#{2}"})
	int deleteRepair2(String eqptType,String snId,String repairState);
		
	@Delete(value = {"delete from res_repair_record where id=#{0}"})
	int deleteRepair(String id);
}
